package com.wangzhen.codebase.apidemo;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

public class ExecutorsDemo {


    public static void main(String[] args) {
        //ExecutorService executorService = Executors.newFixedThreadPool(10);

        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                2,
                4,
                60,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10),
                new ThreadFactory() {
                    private final AtomicInteger integer = new AtomicInteger();
                    @Override
                    public Thread newThread(Runnable r) {
                        Thread thread = new Thread(r);
                        thread.setName("my-threade-pool1-"+ integer.getAndIncrement());
                        return thread;
                    }
                }, new RejectedExecutionHandler() {
                    @Override
                    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
                        System.out.println("----->tiger reject");
                    }
                });


        for (int i = 0; i < 100; i++) {
            executor.execute(()-> {
                System.out.printf("thread name :%s ---- hello world \n", Thread.currentThread().getName());
            });
        }

    }
}
